home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
cstdio.arc
/
SRC.ARC
/
MTYBUF.C
< prev
next >
Wrap
C/C++ Source or Header
|
1984-07-23
|
763b
|
39 lines
/* mtybuf.c - empty buffer to file.
(C) Copyright 1984 Gregory R. Mansfield - All Rights Reserved.
G. R. Mansfield. 84/06/05.
Ver 1.1-4723.
*/
#include "stdio.h"
int _mtybuf(c, fp)
char c;
FILE *fp;
{
int l;
if ((fp->_flag & _WRITE) == 0)
return(ERR);
if (fp->_base == NULL) { /* find buffer space */
if (fp->_flag & _UNBUF) { /* unbuffered */
write(fp->_fd, &c, 1);
++fp->_cnt;
return(c);
}
if ((fp->_base = malloc(BUFSIZE, 1)) == NULL) {
wcs("no buffer space for file\n");
exit(2);
}
}
else {
l = fp->_ptr - fp->_base;
if (write(fp->_fd, fp->_base, l) != l) {
fp->_flag |= _ERR;
return(ERR);
}
}
fp->_ptr = fp->_base;
fp->_cnt = BUFSIZE - 1;
return(*fp->_ptr++ = c);
}